package vehement.game.entities;

//import javax.microedition.khronos.opengles.GL10;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;

import vehement.game.GameThread;
import vehement.game.Globals;
import vehement.game.graphics.Ob;
import vehement.game.interfaces.Drawable;
import vehement.game.interfaces.Updateable;

public class Fireball implements Updateable, Drawable {
	public org.lwjgl.util.vector.Vector3f position;
	public Vector3f velocity;
	public Vector3f acceleration;
	public float facing;
	
	public float timeToLive = Globals.fireBallTime;
	
	public Fireball(Vector3f initPos, Vector3f initVel){
		position = initPos;
		velocity = initVel;
		facing = (float) (((180.f/Math.PI)* Math.atan2(velocity.x, velocity.y)));
//		acceleration = new Vector3f(0,0,0);
	}

	public void update(float delta) {
		
//		Vector3f.add(velocity,(Vector3f) acceleration.scale(delta) , velocity);
		Vector3f.add(position,(Vector3f) velocity.scale(delta), position);
		timeToLive -= delta;
		
		//Test collision
		boolean collision = false;
		if (timeToLive <= 0.f){
			collision = true; //do cheapest checks first
		}else{
			//test for tileset collisions
			//test for actual collisions
		}
		
		if (collision){
		//	collide();
		}
	}
	
	
	//TODO: implement this
	public void collide(){
		//find all targets within distance x^2
		//apply damage
		
		//remove fireball
		GameThread.world.drawables.remove(this);
		GameThread.world.updateables.remove(this);
	};

	//Draw a billboard to represent the fireball
	public void draw() {
		
		// TODO: Find a way to do this without a trig call
		GL11.glPushMatrix();
		//We need to recalculate this, as we have acceleration.  
		//Therego, we need to nix accel, or reclac this
		GL11.glRotatef( facing, 0, 0, 1);
		GL11.glTranslatef(position.x, position.y, position.z);

		//GL11.glTranslatef(rotation.x, y, z)
		Ob.fireball.draw();
		GL11.glPopMatrix();
		
	}

}
